package com.resource.transactions.controller;

import com.resource.transactions.entities.Result;
import com.resource.transactions.entities.ResultCode;
import com.resource.transactions.service.SolrService;
import org.apache.solr.client.solrj.SolrServerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
public class ResourceController {

    private final SolrService solrService;

    @Autowired
    public ResourceController(SolrService solrService) {
        this.solrService = solrService;
    }

    @PostMapping("resourceSearch/{resourceName}")
    public Result resourceSearch(@PathVariable("resourceName") String name) throws IOException, SolrServerException {
        return new Result(ResultCode.SUCCESS, solrService.query(name));
    }


}
